package com.heny.demo.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author :wushen
 * @since :2025/5/11 16:44
 */
@Component
public class FileParseStrategyFactory {

    private final Map<String, FileParseStrategy> strategyMap = new HashMap<>();

    @Autowired
    public FileParseStrategyFactory(Map<String, FileParseStrategy> strategyMap) {
        strategyMap.forEach((key, value) -> this.strategyMap.put(key.toLowerCase(), value));
    }

    public FileParseStrategy getStrategy(String fileExtension) {
        FileParseStrategy strategy = strategyMap.get(fileExtension.toLowerCase());
        if (strategy == null) {
            throw new IllegalArgumentException("不支持的文件类型: " + fileExtension);
        }
        return strategy;
    }
}    